Component({
  data: {
    active: 0,
    list: [
      {
        url: "/pages/index/index",
        icon: "home-o",
        text: "主页",
      },
      {
        url: "/pages/code/index",
        icon: "add",
        text: "发布",
      },
      {
        url: "/pages/mine/index",
        icon: "friends-o",
        text: "我的",
      },
    ],
  },
  attached() {},
  methods: {
    onChange(e) {
      console.log(e, "e");
      wx.switchTab({
        url: this.data.list[e.detail].url,
      });
      this.setData({ active: e.detail });
    },
    init() {
      const page = getCurrentPages().pop();
      this.setData({
        active: this.data.list.findIndex(
          (item) => item.url === `/${page.route}`
        ),
      });
    },
  },
});
